/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved.
 * <a>http://www.cqcis.com</a>
 */
package com.firebird.fb.interceptor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author qiuxj create 2009-6-8
 *
 */
public class MethodInvokeInterceptor implements MethodInterceptor {

	protected final Log logger = LogFactory.getLog(this.getClass());
	
	public Object invoke(MethodInvocation invocation) throws Throwable {
		String arg1 = invocation.getThis().getClass().getName();
		String arg2 = invocation.getMethod().getName();
		Object[] arg3 = invocation.getArguments();
		//logger.warn("arg1:\n" + arg1 + "\narg2:\n" + arg2 + "\narg3:\n" + arg3);
		String invokeDetail = arg1 + arg2 + arg3;
		Long startTime = System.currentTimeMillis();
		Object result = invocation.proceed();
		Long endTime = System.currentTimeMillis();
		logger.info("\nCurrently Invoke Method Is :" + invokeDetail + "\nInvoke This Method Spend Time Is :" + (endTime - startTime));
		return result;
	}
	
}
